package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import gentle.base.BaseController;
import gentle.entity.MembersUser;
import gentle.entity.PointRewordInfo;
import gentle.entity.SearchMembersUser;
import gentle.entity.SearchPointRewordInfo;
import gentle.factory.PageFactory;
import gentle.service.CustomerMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author py
 * @Date 2019年4月19日23:15:54
 */
@Controller
@RequestMapping("/customerMember")
public class CustomerMemberController extends BaseController {

    @Autowired
    CustomerMemberService memberService;

    /**
     * 会员列表查询
     */
    @RequestMapping("/customerMemberList")
    @ResponseBody
    public Object customerMemberList(SearchMembersUser info, HttpServletRequest request) {
        if (info.getOutpatientName() == "" || info.getOutpatientName() == null || info.getOutpatientName() == "null") {
            return null;
        } else {
            Page<MembersUser> page = new PageFactory<MembersUser>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<MembersUser> list = memberService.selectCustomerMemberList(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = memberService.selectCustomerMemberList(page, info);
                }
                page.setTotal(memberService.getQueryPagesMemberListCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

}